begintownscript;
variables;
short choice,i,j,k,level,levelmod;

body;

beginstate init_state;
if(get_flag(255,0) == 0){
	force_view_center(0,0);
	force_instant_terrain_redraw();
	i = -1;
	k = 0;
	while(k <= 3){
		if((char_ok(k) == 1) && (get_species(k) == 0) && (get_level(k) < 100))
			if(i == -1)
				i = k;
		k = k + 1;
	}
	if(i == -1){
		message_dialog("You must have a human in your party in order to play. You also cannot play if you are using a god party. Please reenter with an appropriate party.","");
		end_scenario(0);
	}
	reset_dialog();
	add_dialog_str(0,"Scenario by Lazarus. Contact me at mcleod989@yahoo.com with bug reports, comments, and concerns.",0);
	add_dialog_str(1,"It is crucial that you read the README file before playing this scenario. This scenario changes point of view fairly often, and it is important that you switch your character's graphic to reflect these changes. Again this is explained in the README.",0);
	add_dialog_str(2,"You will be playing as a singleton all scenario, but it doesn't matter what party you enter with as long as it isn't a god party, and has a human in it.",0);
	add_dialog_str(3,"At the start your party will be cut down to one, and it will remain that way until you leave scenario. When you leave scenario your party will be restored, your items and spells returned, and you will be sent on your merry way.",0);
	add_dialog_str(4,"Enjoy",100);
	run_dialog(1);
	
	k = 0;
	while(k <= 3){
		if(char_ok(k) == 1){
			set_flag(230,k,1);
			relocate_character(k,1,33 - (3 * k));
			if(k == i)
				kill_char(k,1,0);
			else{
				set_name(k,"");
				kill_char(k,7,0);
			}
		}
		k = k + 1;
	}
	k = 0;
	while(k <= 31){
		set_flag(150 + k,0,get_stat(i,k));
		k = k + 1;
	}
	k = 0;
	while(k <= 22){
		set_flag(150 + k,1,char_has_trait(i,k));
		k = k + 1;
	}
	k = 0;
	while(k <= 19){
		set_flag(150 + k,2,get_spell_level(i,0,k));
		set_flag(150 + k,3,get_spell_level(i,1,k));	
		k = k + 1;
	}
	set_flag(149,4,get_char_skill_pts(i));
	k = coins_amount();
	set_flag(149,2,j/256);
	set_flag(149,3,j%256);
	set_flag(149,0,get_level(i));
	split_off_one_char(24,45,0,i);
	set_flag(255,0,1);
	relocate_character(i,25,45);
	set_character_facing(i,0);
	set_character_pose(i,0);
	force_view_center(25,45);
	force_instant_terrain_redraw();	
	
	reset_dialog();
	add_dialog_str(0,"You pick up your pace as the sun sinks lower and lower on the horizon; the sooner you get to Cigosal the better. It's dangerous for an unarmed man to travel the Gray Road alone, even during the light of day. At night-- well it's not a pleasant prospect.",0);
	add_dialog_str(1,"You certainly wouldn't be travelling this late if you didn't absolutey have to. You left New Haven several hours later than you'd intended too; it had been difficult to leave behind the generous crowds.",0);
	add_dialog_str(2,"You made a pretty penny in the extra time you spent there, but now you're paying for it. You're sure the bandits in these parts will appreciate those few extra coins you picked up.",0);
	add_dialog_str(3,"You chuckle to yourself, but it turns into a sigh. If you get to Cigosal safely you'll consider youself fortunate. If you get there with your purse still intact you'll consider it a miracle.",0);
	run_dialog(1);

	i = 0;
	while(char_ok(i) == 0){
		i = i + 1;
	}
	j = 0;
	while(j <= 22){
		set_char_trait(i,j,0);
		j = j + 1;
	}

	level = (5 - get_level(i));
	set_level(i,5);
	while(level < 1){
		change_char_xp(i,-25 * 100);
		level = level + 1;
	}
	level = 5;
	while(level > 1){
		change_char_xp(i,500);
		change_char_xp(i,500);
		level = level - 1;
	}
	j = 0;
	while(j <= 19){
		if(get_spell_level(i,0,j) > 0)
			change_spell_level(i,0,j,-1* get_spell_level(i,0,j));
		if(get_spell_level(i,1,j) > 0)
			change_spell_level(i,1,j,-1 * get_spell_level(i,1,j));
		j = j + 1;
	}
	change_pc_skill_pts(i,-1 * (get_char_skill_pts(i)));
	alter_stat(i,0,3 - get_stat(i,0)); //- Strength
	alter_stat(i,0,3 - get_stat(i,0)); //- Strength
	alter_stat(i,1,3 - get_stat(i,1)); // - Dexterity
	alter_stat(i,1,3 - get_stat(i,1)); // - Dexterity
	alter_stat(i,2,6 - get_stat(i,2)); // - Intelligence
	alter_stat(i,2,6 - get_stat(i,2)); // - Intelligence
	alter_stat(i,3,4 - get_stat(i,3)); // - Endurance
	alter_stat(i,3,4 - get_stat(i,3)); // - Endurance
	alter_stat(i,4,0 - get_stat(i,4)); // - Melee Weapons
	alter_stat(i,5,0 - get_stat(i,5)); // - Pole Weapons
	alter_stat(i,6,0 - get_stat(i,6)); // - Bows
	alter_stat(i,7,0 - get_stat(i,7)); // - Thrown Missiles
	alter_stat(i,8,0 - get_stat(i,8)); // - Hardiness
	alter_stat(i,9,0 - get_stat(i,9)); // - Defense
	alter_stat(i,10,0 - get_stat(i,10)); // - Assassination
	alter_stat(i,11,0 - get_stat(i,11)); // - Mage Spells
	alter_stat(i,12,0 - get_stat(i,12)); // - Priest Spells
	alter_stat(i,13,0 - get_stat(i,13)); // - Arcane Lore
	alter_stat(i,14,0 - get_stat(i,14)); // - Potion Making
	alter_stat(i,15,0 - get_stat(i,15)); // - Tool Use
	alter_stat(i,16,0 - get_stat(i,16)); // - Nature Lore
	alter_stat(i,17,0 - get_stat(i,17)); // - First Aid
	alter_stat(i,18,0 - get_stat(i,18)); // - Luck
	alter_stat(i,19,0 - get_stat(i,19)); // - Quick Strike
	alter_stat(i,20,0 - get_stat(i,20)); // - Parry
	alter_stat(i,21,0 - get_stat(i,21)); // - Blademaster
	alter_stat(i,22,0 - get_stat(i,22)); // - Anatomy
	alter_stat(i,23,0 - get_stat(i,23)); // - Gymnastics
	alter_stat(i,24,0 - get_stat(i,24)); // - Pathfinder
	alter_stat(i,25,0 - get_stat(i,25)); // - Magery
	alter_stat(i,26,0 - get_stat(i,26)); // - Resistance
	alter_stat(i,27,0 - get_stat(i,27)); // - Magical Efficiency
	alter_stat(i,28,0 - get_stat(i,28)); // - Lethal Blow
	alter_stat(i,29,0 - get_stat(i,29)); // - Riposte
	alter_stat(i,30,0 - get_stat(i,30)); // - Sharpshooter

	pay_coins(coins_amount());
	change_coins(get_flag(240,0));
	set_name(i,"Bard");
	reward_give(14);
	reward_give(19);
	reward_give(17);
	change_char_energy(i,999);
	change_char_health(i,-999);
	change_char_health(i,999);
	revive_party();
	if(get_flag(31,2) == 1)
	reward_give(169);
	level = 0;
	while(level <= 63){
		print_str(" ");
		level = level + 1;
	}
	print_str_color("Now entering: The Gray Road",3);
	}
else{
	i = 0;
	j = 0;
	while(i <= 3){
		if(char_ok(i) == 1){
			relocate_character(i,5,35 + j);
			j = j + 1;
		}
		i = i + 1;
	}
	k = 0;
	while(k <= 3){
		if(char_ok(k) == 1)
			flip_terrain(3,33 - (3 * k));
		k = k + 1;
	}
	force_view_center(5,35);
	if((get_flag(250,0) == 3) || (get_flag(250,1) == 3) || (get_flag(250,2) == 3) || (get_flag(250,3) == 3) || (get_flag(250,4) == 3))
		flip_terrain(3,19);
	force_instant_terrain_redraw();
	level = 0;
	while(level <= 63){
		print_str(" ");
		level = level + 1;
	}
	print_str_color("Now entering: The Story's End",3);
}
set_char_dialogue_pic(6,307,0);
set_name(6,"Traveller");
break;

beginstate exit_state;
break;

beginstate start_state;

break;

beginstate 10;
if(get_flag(32,0) == 0){
	set_flag(32,0,1);
	message_dialog("As if the threat of imminent death wasn't even to worry about, you also have your performance for the infamously hard-to-please Lord Aradin looming, and don't have any new material to add to your act.","You struggle to come up with some new song or dance, but the shadows along the side of the road, and the bandits that could be hiding in them, are just too distracting.");
}
break;

beginstate 11;
if(get_flag(32,1) == 0){
	set_flag(32,1,1);
	message_dialog("You fully expect to get booed out of Aradin's hall, but not showing up to your appointment tomorrow night would be many times worse. Many bards have been banned from the city of Cigosal because of Aradin's wrath.","Which is why you're going to be travelling late into the night. Being late could very well be more costly than being waylaid.");
}
break;

beginstate 12;
if(get_flag(32,2) == 0){
	set_flag(32,2,1);
	reset_dialog();
	add_dialog_str(0,"Your heart leaps and all thoughts of Lord Aradin flee when you see the man standing in the road ahead. The sunlight is fading fast and you can't see much of him, except that he's a large, broad-shouldered man.",0);
	add_dialog_str(1,"He holds a massive sack, which rests on the ground, but doesn't appear to have any weapons.",0);
	add_dialog_str(2,"He doesn't APPEAR to be hostile, but that doesn't really mean anything. He just stands there, waiting. Odd behavior, but not necessarily threatening. You approach cautiously, trying to avoid eye contact.",0);
	run_dialog(1);
}
break;

beginstate 13;
if(get_flag(32,3) == 0)
	set_flag(32,3,1);
break;

beginstate 14;
if(get_flag(32,3) == 1){
	print_str_color("Not yet!",1);
	block_entry(1);
}
break;

beginstate 15;
//north
block_entry(1);
if(get_flag(32,4) == 0){
	set_flag(32,4,1);
	reset_dialog();
	add_dialog_str(0,"As you continue on the road to Cigosal, a weird feeling of uneasiness begins to nag at the back of your mind. It takes you a while to realise you're actually still preoccupied by your strange encounter with the traveller.",0);
	add_dialog_str(1,"_If you want to hear a tale that will impress even your Lord Aridan, then the Tabard is your spot._",0);
	add_dialog_str(2,"You find, to your surprise, that you've come to a halt. You shake your head and begin to walk again, but a short distance later you again catch yourself standing still. You just can't shake the traveller's words from your head.",0);
	add_dialog_str(3,"You find yourself looking back down the road, towards the intersection where you first met him. Perhaps stopping for a drink at that tavern he kept talking about-- the Tabard?-- wouldn't be such a bad idea after all....",0);
	add_dialog_str(4,"_You won't regret it._",0);
	run_dialog(1);
}
else
	message_dialog("You set off deliberately, with the intention of overcoming the strange absentmindedness that has come over you. Yet you only make it a few steps before you catch yourself standing still again.","You can't seem to make any progress. You keep feeling drawn back towards the intersection where you met the traveller.");
break;

beginstate 16;
if(get_flag(32,5) == 0){
	set_flag(32,5,1);
	reset_dialog();
	add_dialog_str(0,"The realization that you're actually heading towards the Tabard Inn makes you feel so ridiculous that you stop and begin to turn around.",0);
	add_dialog_str(1,"But something stops you. The traveller was certainly peculiar, ridiculous even, but then again it's peculiar folks who lead to the best stories of all. There's something about this whole thing that has you curious.",0);
	add_dialog_str(2,"You know that you have hours of travel ahead before you reach Cigosal-- and you MUST reach Cigosal before the night's over-- but still you keep finding reasons to take this slight detour.",0);
	add_dialog_str(3,"You need a rest; your throat is parched and your canteen is near empty; you have plenty of time for this short stop. The excuses go on.",0);
	add_dialog_str(4,"And even if nothing comes of this-- even if the traveller was a loon and this Tabard Inn is no different than any of its dull brethren-- you'll have some time to clear your mind and think about what you'll do when you get to Aridan's court.",0);
	add_dialog_str(5,"It's definitely a win-win..... and so you continue to stifle the voice in the back of your mind that says this certainly is nothing but a wild goose chase, and continue travelling west.",0);
	run_dialog(1);
	set_character_facing(i,0);
	move_to_new_town(31,23,46);
}

beginstate 30;
if(get_flag(250,0) < 3){
	block_entry(1);
	print_str_color("The chest won't open.",1);
}
break;

beginstate 31;
if(get_flag(250,1) < 3){
	block_entry(1);
	print_str_color("The chest won't open.",1);
}
break;

beginstate 32;
if(get_flag(250,2) < 3){
	block_entry(1);
	print_str_color("The chest won't open.",1);
}
break;

beginstate 33;
if(get_flag(250,3) < 3){
	block_entry(1);
	print_str_color("The chest won't open.",1);
}
break;

beginstate 34;
if(get_flag(250,4) < 3){
	block_entry(1);
	print_str_color("The chest won't open.",1);
}
break;


beginstate 100;
block_entry(1);
break;

beginstate 104;
block_entry(1);
reset_dialog();
add_dialog_str(0,"You are about to depart the scenario for good. Are you sure you have all your gear, and are ready to leave?",0);
add_dialog_choice(0,"Yeah, it's time to go.");
add_dialog_choice(1,"Hold on a minute, I might have left something.");
choice = run_dialog(1);
if(choice == 2)
	end();
if(get_flag(250,5) == 5)
	end_scenario(1);
else
	end_scenario(0);
break;